//
//  HWUniversal.swift
//  WoWoLiveAssistant
//
//  Created by 王昌健 on 2021/10/28.
//

import UIKit
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height

let widthScale = CGFloat(Double(String(format: "%.2f", screenWidth/375)) ?? 0)
//let widthScale = screenWidth/375
let heightScale = screenHeight/812
let scale = UIScreen.main.scale
let h = ceil(0.5 * scale) / scale
let blackTextColor = UIColor.colorWithHexString(hexString: "#333333")

var currentWindow: UIWindow? {
    if #available(iOS 13.0, *) {
        if let window = UIApplication.shared.connectedScenes
            .filter({$0.activationState == .foregroundActive})
            .map({$0 as? UIWindowScene})
            .compactMap({$0})
            .first?.windows
            .filter({$0.isKeyWindow}).first{
            return window
        }else if let window = UIApplication.shared.delegate?.window{
            return window
        }else{
            return nil
        }
    } else {
        if let window = UIApplication.shared.delegate?.window{
            return window
        }else{
            return nil
        }
    }
}
class HWUniversal: NSObject {
    
    
    func isIphone8() -> Bool {
        if screenWidth == 375 && screenHeight == 667 {
            return true
        }
        return false
    }
    func isIphone8Plus() -> Bool {
        if screenWidth == 414 && screenHeight == 736 {
            return true
        }
        return false
    }
    
}

extension HWUniversal {
    
    /// 获取当前窗口控制器
    /// - Returns: 返回控制器
    @objc class public func getCurrentVc() -> UIViewController{
        let rootVc = currentWindow?.rootViewController
        let currentVc = getCurrentVcFrom(rootVc!)
        return currentVc
    }
    
    class private func getCurrentVcFrom(_ rootVc:UIViewController) -> UIViewController{
        var currentVc:UIViewController
        var rootCtr = rootVc
        if(rootCtr.presentedViewController != nil) {
            rootCtr = rootVc.presentedViewController!
        }
        if rootVc.isKind(of:UITabBarController.classForCoder()) {
            currentVc = getCurrentVcFrom((rootVc as! UITabBarController).selectedViewController!)
        }else if rootVc.isKind(of:UINavigationController.classForCoder()){
            currentVc = getCurrentVcFrom((rootVc as! UINavigationController).visibleViewController!)
        }else{
            currentVc = rootCtr
        }
        return currentVc
    }
    
    //View转Image
    class public func convertViewToImage(v:UIView) -> UIImage {
        //第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示透明效果，需要传false，否则传true。第三个参数就是屏幕密度了，关键就是第三个参数 UIScreen.main.scale
        UIGraphicsBeginImageContextWithOptions(v.bounds.size, false, UIScreen.main.scale)
        let ctx = UIGraphicsGetCurrentContext()!
        v.layer.render(in: ctx)
        let newImage = UIGraphicsGetImageFromCurrentImageContext()!
        
        UIGraphicsEndImageContext()
        
        return newImage
    }
    
    
    /// 打印系统字体名
    class public func printFontName() -> Void {
        for family: String in UIFont.familyNames {
            print("\(family)")
            
            for names: String in UIFont.fontNames(forFamilyName: family) {
                print("\(names)")
            }
        }
    }
    ///字典转jsonString
    class public func getJSONStringFromDictionary(dictionary:NSDictionary) -> String {
        if (!JSONSerialization.isValidJSONObject(dictionary)) {
            print("无法解析出JSONString")
            return ""
        }
        let data : NSData! = try? JSONSerialization.data(withJSONObject: dictionary, options: []) as NSData?
        let JSONString = NSString(data:data as Data,encoding: String.Encoding.utf8.rawValue)
        
        
        
        return JSONString! as String
        
    }
    ///jsonString转字典
    class public func getDictionaryFromJSONString(jsonString:String) ->NSDictionary{
        
        let jsonData:Data = jsonString.data(using: .utf8)!
        
        let dict = try? JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers)
        if dict != nil {
            return dict as! NSDictionary
        }
        return NSDictionary()
    }
    
}

extension Date {
    /// 获取当前 秒级 时间戳 - 10位
    var timeStamp : String {
        let timeInterval: TimeInterval = self.timeIntervalSince1970
        let timeStamp = Int(timeInterval)
        return "\(timeStamp)"
    }
    
    /// 获取当前 毫秒级 时间戳 - 13位
    var milliStamp : String {
        let timeInterval: TimeInterval = self.timeIntervalSince1970
        let millisecond = CLongLong(round(timeInterval*1000))
        return "\(millisecond)"
    }
}




extension HWUniversal {
    // Data转JSON字符串
    class func DataToJSONString(data: Data) -> String? {
        
        let JSONString = String(data: data, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
        return JSONString
    }
    
    //Data转字典
    class func DataToDictionary(data:Data) ->Dictionary<String, Any>? {
        
        do{
            
            let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers)
            let dic = json as! Dictionary<String, Any>
            return dic
        }catch _ {
            
            return nil
        }
    }
    
    
    // JSON字符串转Data
    @objc class func JSONStringToData(json: String) -> Data? {
        
        let jsonData = json.data(using: String.Encoding.utf8, allowLossyConversion: false)
        return jsonData
    }
    
    // JSONString转换为字典
    
    class func JSONStringToDictionary(jsonString:String) ->NSDictionary{
        
        let jsonData:Data = jsonString.data(using: .utf8)!
        
        let dict = try? JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers)
        if dict != nil {
            return dict as! NSDictionary
        }
        return NSDictionary()
    }
    
    // JSONString转换为数组
    class func JSONStringToArray(jsonString:String) ->NSArray{
        
        let jsonData:Data = jsonString.data(using: .utf8)!
        
        let array = try? JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers)
        if array != nil {
            return array as! NSArray
        }
        return array as! NSArray
        
    }
    
    // Data转JSON(对象)
    class func DataToJSONObject(data: Data) -> Any? {
        
        do {
            return try JSONSerialization.jsonObject(with: data , options: .mutableContainers) as AnyObject
        } catch {
            print(error)
        }
        return nil
    }
    
    // JSON(对象)转Data
    class func JSONObjectToData(json: Any) -> Data? {
        
        do {
            return try JSONSerialization.data(withJSONObject: json, options: [])
        } catch {
            print(error)
        }
        return nil
    }
    
    // 字典|数组 转JSON字符串
    class func ObjectToJSONString(object: Any) -> String? {
        
        do {
            let data = try JSONSerialization.data(withJSONObject: object, options: [])
            let JSONString = String(data: data, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
            return JSONString
        } catch {
            print(error)
        }
        return nil
    }
    
    class func convertDictionAryToJson(dic:NSDictionary) -> String {
        let data = try? JSONSerialization.data(withJSONObject: dic, options: JSONSerialization.WritingOptions.init(rawValue: 0))
        let jsonStr = String(data: data!, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
        return jsonStr!
    }
    
    
    // 字典|数组 转Data
    class func ObjectToData(object: Any) -> Data? {
        
        do {
            return try JSONSerialization.data(withJSONObject: object, options: [])
        } catch {
            print(error)
        }
        return nil
        
    }
    
    class func ModelToDic(model:AnyObject)->NSDictionary{
        
        let redic = NSMutableDictionary()
        
        let mirror: Mirror = Mirror(reflecting: model)
        
        for p in mirror.children{
            
            if(p.label! != ""){
                
                redic.setValue("\(p.value)", forKey: p.label!)
                
            }
            
        }
        
        return redic
        
    }
    
    class func DicToModel(dic:Dictionary<String,String>,model:AnyObject){
        
        /// 这里将字典中所有KEY  和 值  都转换为  STRING类型，目的只有一个运用 OBJ的 setValue方法，给 这个对象赋值
        
        /// 这就完成了，字典和对象的转换
        
        let mirrotwo:Mirror = Mirror(reflecting: dic)
        
        for p in mirrotwo.children {
            
            let (key,value) = (p.value as! (String,String))
            
            //循环出字典中的每一对key - value 都是String类型，然后将这个类型赋值给model
            
            //这一次遍历当前需要赋值对象的属性，是因为需要判断当前对象是否有这个属性，如果有才会给他赋值，如果没有就略过
            
            //mirrorModel是当前需要赋值的对象的反射对象，他的LABEL就是对象的属性，value就是数值，但是只读的，
            
            //所以只能通过model.setValue来赋值
            
            let mirrorModel = Mirror(reflecting: model)
            
            for eachItem in mirrorModel.children {
                
                if(eachItem.label! == key){
                    
                    //这一步简直爆炸的方法
                    
                    model.setValue(value, forKey: key)
                    
                }
                
            }
            
        }
        
    }
}

extension NSObject {
    func getTextHeigh(textStr :  String, font : UIFont, width : CGFloat)  -> CGFloat{
        
        let normalText : NSString = textStr as NSString
        
        let size = CGSize(width: width, height:1000) //CGSizeMake(width,1000)
        
        let dic = NSDictionary(object: font, forKey : kCTFontAttributeName as! NSCopying)
        
        let stringSize = normalText.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: dic as? [NSAttributedString.Key:Any], context:nil).size
        
        return stringSize.height
        
    }
    
    //View转Image
    class public func convertCreateImageWithUIView(v:UIView) -> UIImage {
        //        UIGraphicsBeginImageContext(v.bounds.size)
        UIGraphicsBeginImageContextWithOptions(v.bounds.size, true, UIScreen.main.scale)
        let ctx = UIGraphicsGetCurrentContext()!
        v.layer.render(in: ctx)
        let newImage = UIGraphicsGetImageFromCurrentImageContext()!
        
        UIGraphicsEndImageContext()
        
        return newImage
    }
    
    /// base64解码
    class func base64Decoding(encodedString:String)->String
    
    {
        let decodedData = NSData(base64Encoded: encodedString, options: NSData.Base64DecodingOptions.init(rawValue: 0))
        
        let decodedString = NSString(data: decodedData! as Data, encoding: String.Encoding.utf8.rawValue)! as String
        
        return decodedString
        
    }
}


extension UIImage {
    
    class func createQRCodeImage(content: String, size: CGSize) -> UIImage {
        let stringData = content.data(using: String.Encoding.utf8)
        
        let qrFilter = CIFilter(name: "CIQRCodeGenerator")
        qrFilter?.setValue(stringData, forKey: "inputMessage")
        qrFilter?.setValue("H", forKey: "inputCorrectionLevel")
        
        let colorFilter = CIFilter(name: "CIFalseColor")
        colorFilter?.setDefaults()
        colorFilter?.setValuesForKeys(["inputImage" : (qrFilter?.outputImage)!,"inputColor0":CIColor.init(cgColor: UIColor.black.cgColor),"inputColor1":CIColor.init(cgColor: UIColor.white.cgColor)])
        
        let qrImage = colorFilter?.outputImage
        let cgImage = CIContext(options: nil).createCGImage(qrImage!, from: (qrImage?.extent)!)
        
        UIGraphicsBeginImageContext(size)
        let context = UIGraphicsGetCurrentContext()
        context!.interpolationQuality = .none
        context!.scaleBy(x: 1.0, y: -1.0)
        context?.draw(cgImage!, in: (context?.boundingBoxOfClipPath)!)
        let codeImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return codeImage!
    }
    
}

extension UIImage {
    
    class func createImageFrom(color: UIColor, width: CGFloat = 1, height: CGFloat = 1) -> UIImage? {
        let rect = CGRect(x: 0.0, y: 0.0, width: width, height: height)
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()
        context?.setFillColor(color.cgColor)
        context?.fill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image ?? nil
    }
    
    class func createImageFrom(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) -> UIImage? {
        let rect = CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height)
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()
        context?.setFillColor(color.cgColor)
        context?.fill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image ?? nil
    }
}


extension String {
    func searchStrRange(_ matchStr: String) -> [NSRange] {
        var selfStr = self as NSString
        var withStr = Array(repeating: "X", count: (matchStr as NSString).length).joined(separator: "") //辅助字符串
        if matchStr == withStr { withStr = withStr.lowercased() } //临时处理辅助字符串差错
        var allRange = [NSRange]()
        while selfStr.range(of: matchStr).location != NSNotFound {
            let range = selfStr.range(of: matchStr)
            allRange.append(NSRange(location: range.location,length: range.length))
            selfStr = selfStr.replacingCharacters(in: NSMakeRange(range.location, range.length), with: withStr) as NSString
        }
        return allRange
    }
    
    //时间戳转成字符串
    static func timeIntervalChangeToTimeStr(timeInterval:Double, _ dateFormat:String? = "yyyy-MM-dd HH:mm:ss") -> String {
        let date:Date = Date.init(timeIntervalSince1970: timeInterval)
        let formatter = DateFormatter.init()
        if dateFormat == nil {
            formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        }else{
            formatter.dateFormat = dateFormat
        }
        return formatter.string(from: date as Date)
    }
    
    //MARK:- 字符串转时间戳
    func timeStrChangeTotimeInterval(_ dateFormat:String? = "yyyy-MM-dd HH:mm:ss") -> String {
        if self.isEmpty {
            return ""
        }
        let format = DateFormatter.init()
        format.dateStyle = .medium
        format.timeStyle = .short
        if dateFormat == nil {
            format.dateFormat = "yyyy-MM-dd HH:mm:ss"
        }else{
            format.dateFormat = dateFormat
        }
        let date = format.date(from: self)
        return String(date!.timeIntervalSince1970)
    }
    
    /// 转化Html字符串
    func toHtmlAttributedText() -> NSMutableAttributedString? {
        
        guard let data = self.data(using: String.Encoding.utf8, allowLossyConversion: true) else { return nil }
        
        let options: [NSMutableAttributedString.DocumentReadingOptionKey : Any] = [
            
            NSMutableAttributedString.DocumentReadingOptionKey.characterEncoding : String.Encoding.utf8.rawValue,
            
            NSMutableAttributedString.DocumentReadingOptionKey.documentType : NSMutableAttributedString.DocumentType.html,
        ]
        
        let htmlString = try? NSMutableAttributedString(data: data, options: options, documentAttributes: nil)
        
        return htmlString
    }
    
}

extension StringProtocol {
    func limitedLengthLabelText(limit:Int) -> String {
        var count = 0
        for index in indices {
            count += 1
            if count == limit {
                let upperBound = self.index(after: index)
                return String(self[..<upperBound]) + (upperBound < endIndex ? "…" : "") }
        }
        return String(self)
    }
}

extension NSObject {
    @objc class func pushController(type:String,urlString:String) -> Void {
        if urlString.count>0 {
            let webVC = XMGWebViewController()
            webVC.url = URL(string: urlString)
            HWUniversal.getCurrentVc().navigationController?.pushViewController(webVC, animated: true)
        }else if type == "316" {
            ///游享会员
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWOpenVipController(), animated: true)
        }else if type == "346" {
            ///游戏社区
            
            if HWGlobalConst.shared.baseUrl.contains("pro.94wan.com") {
                let community = HWGameCommunityController()
                community.communityId = ""
                HWUniversal.getCurrentVc().navigationController?.pushViewController(community, animated: true)
            } else {
                HWUniversal.getCurrentVc().navigationController?.pushViewController(HWGameCommunityAllListController(), animated: true)
            }
            
        }else if type == "367" {
            ///云游戏
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWCloudGameController(), animated: true)
        }else if type == "301" {
            ///我的礼包
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWMyGiftBagViewController(), animated: true)
        }else if type == "302" {
            ///我的账单
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWMyzhangdangQCViewController(), animated: true)
        }else if type == "303" {
            ///角色管理
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWXiaoHaotrumpetInterfaceViewController(), animated: true)
        }else if type == "304" {
            ///我的收藏
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWCollectionViewController(), animated: true)
        }else if type == "305" {
            ///我的绑币
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWMyCurrencyViewController(), animated: true)
        }else if type == "306" {
            ///设置中心
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWSheZhiViewController(), animated: true)
        }else if type == "308" {
            ///安全中心
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWAccountSecurityController(), animated: true)
        }else if type == "309" {
            ///申请返利
        }else if type == "310" {
            ///排行榜
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWPaiHangBangViewController(), animated: true)
        }else if type == "311" {
            ///礼包中心
//            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWGiftBagCenterzhongxingViewController(), animated: true)
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWGiftBagCenterController(), animated: true)
        }else if type == "312" {
            ///开服表
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWTYouXiKaiFuViewController(), animated: true)
        }else if type == "313" {
            ///邀请好友
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWInviteFriendController(), animated: true)
        }else if type == "314" {
            ///领券中心
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWlingjuanzhongxingViewController(), animated: true)
        }else if type == "315" {
            ///我的资产
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWMyAssetsController(), animated: true)
        }else if type == "316" {
            ///游享会员
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWVIPController(), animated: true)
        }else if type == "317" {
            ///我的评论
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWpinglunViewController(), animated: true)
        }else if type == "318" {
            ///关于我们
            let shortVersion:String = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
            let bundleVersion:String = Bundle.main.infoDictionary!["CFBundleVersion"] as! String
            let url = HWGlobalConst.shared.baseUrl + "?ct=app&ac=contact&ios=1&h5=1&version=\(shortVersion)(\(bundleVersion))&member_id=\(UserDefaults.standard.object(forKey: "member_id") ?? "")"
            let webVC = XMGWebViewController()
            webVC.url = URL(string: url)
            HWUniversal.getCurrentVc().navigationController?.pushViewController(webVC, animated: true)
        }else if type == "319" {
            ///抽奖
        }else if type == "320" {
            ///试玩任务
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWGameTestController(), animated: true)
        }else if type == "321" {
            ///签到
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWNewSignInViewController(), animated: true)
        }else if type == "322" {
            ///积分夺宝
        }else if type == "323" {
            ///积分商城
        }else if type == "324" {
            ///领积分
        }else if type == "325" {
            ///交易大厅
        }else if type == "326" {
            ///平台币充值
        }else if type == "327" {
            ///充值返利
        }else if type == "328" {
            ///账号交易
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWxiaohaoSmallTransactionsViewController(), animated: true)
        }else if type == "329" {
            ///积分商城
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWIntegralMallshopViewController(), animated: true)
        }else if type == "330" {
            ///每日签到
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWNewSignInViewController(), animated: true)
        }else if type == "331" {
            ///每日答题
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWQuestionsViewController(), animated: true)
        }else if type == "332" {
            ///小号回收
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWTrumpetViewController(), animated: true)
        }else if type == "333" {
            ///积分任务
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWTaskCenterViewController(), animated: true)
        }else if type == "334" {
            ///VIP福利中心
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWVipCenterController(), animated: true)
        }else if type == "335" {
            ///我的关注
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWGameLiveMyFollowController(), animated: true)
        }else if type == "337" {
            ///省钱卡
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWSaveMoneyCardController(), animated: true)
        }else if type == "339" {
            ///游戏礼包 礼包中心
//            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWGiftBagCenterzhongxingViewController(), animated: true)
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWGiftBagCenterController(), animated: true)
        }else if type == "364" {
            /// 直播
            (((HWUniversal.getCurrentVc().tabBarController as! HWTabBarController1).viewControllers[2] as! HWNavigationViewController).viewControllers[0] as!HWCircleViewController).selectLive = true
            (((HWUniversal.getCurrentVc().tabBarController as! HWTabBarController1).viewControllers[2] as! HWNavigationViewController).viewControllers[0] as!HWCircleViewController).selectCircle = false
            (HWUniversal.getCurrentVc().tabBarController as! HWTabBarController1).selectedIndex = 2
            
        }else if type == "365" {
            /// 圈子
            (((HWUniversal.getCurrentVc().tabBarController as! HWTabBarController1).viewControllers[2] as! HWNavigationViewController).viewControllers[0] as!HWCircleViewController).selectCircle = true
            (((HWUniversal.getCurrentVc().tabBarController as! HWTabBarController1).viewControllers[2] as! HWNavigationViewController).viewControllers[0] as!HWCircleViewController).selectLive = false
            (HWUniversal.getCurrentVc().tabBarController as! HWTabBarController1).selectedIndex = 2
        }else if type == "366" {
            /// 一元买号
            (HWUniversal.getCurrentVc().tabBarController as! HWTabBarController1).selectedIndex = 3
        }else if type == "367" {
            ///云游戏
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWCloudGameController(), animated: true)
        }else if type == "368" {
            /// 群聊推荐
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWGroupChatRecommendController(), animated: true)
        }else if type == "369" {
            /// 小游戏
            HWUniversal.getCurrentVc().navigationController?.pushViewController(HWQQGameController(), animated: true)
        } else if type == "370" {
            ///多量游戏试玩sdk
            var encryString = HWLocallyStoredData.getLoginUserID()
            encryString = encryString.replacingOccurrences(of: "_", with: "+")
            let userId = HWAES128.aes128Decrypt(encryString, key: "mtetbpryjhdxmnhx")
            DyAdApi.presentListViewController(HWUniversal.getCurrentVc(), userId: userId, advertType: 0)
        }else {
            
        }
    }
}

extension NSObject {
    class func reLogin(message:String) -> Void {
        HWLocallyStoredData.setUserID("")
        UserDefaults.standard.removeObject(forKey: "userHeadImage")
        let alert  = UIAlertController.init(title: "提示", message: message, preferredStyle: UIAlertController.Style.alert)
//        let cancel = UIAlertAction.init(title: "取消", style: UIAlertAction.Style.default) { aciton in
//            
//        }
        
        let sure = UIAlertAction.init(title: "重新登录", style: UIAlertAction.Style.default) { action in
            let loginController = HWLoginController()
            HWUniversal.getCurrentVc().navigationController?.pushViewController(loginController, animated: true)
        }
        
//        alert.addAction(cancel)
        alert.addAction(sure)
        
        HWUniversal.getCurrentVc().present(alert, animated: true, completion: nil)
    }
}
